<template>
<div class="layerRtb layerRtb-threecolumn">
    <three-title :title="{name: '安装'}"></three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">步骤</p>
            <div class="analyItemCon">
                <p class="col-md-12" v-for="(item, index) in installList" :key="index"><span class="cLightGray pr8">步骤{{ index+1 }}</span><span>{{ item }}</span></p>
            </div>
        </div>
        <div class="analyItem">
            <p class="analyItemTit tx-center">结果</p>
            <div class="analyItemCon">
                <div class="col-md-12">
                    <div class="col-md-8">
                        <rx-upload
                            v-if="(this.twoToThreeInfo.camera === null && Number(this.twoToThreeInfo.install_state) === 0) || (Number(this.twoToThreeInfo.point_state) === 0 && this.twoToThreeInfo.camera !== null && Number(this.twoToThreeInfo.install_state) === 0)"
                            class="fl"
                            :data="{id: 11}"
                            :init="{class: 1, mime: 1}"
                            :elStyle="{width:'70px', height: '70px'}"
                            @success="successUpload">
                            <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                                <a href="javascript:">
                                    <span type="file" value="" class="file"></span>
                                    <em class="bgIcon file-ico"></em>
                                </a>
                            </div>
                        </rx-upload>
                        <rx-viewer :images="imgList" class="fl">
                            <div class="clearfix">
                                <div class="fl" v-for="(item, index) of imgList" :key="index">
                                    <img :src="item | smallImg(70, 70)" :alt="index">
                                </div>
                            </div>
                        </rx-viewer>
                        <rx-viewer :images="installImgsInfo" class="fl">
                            <div class="clearfix">
                                <div class="fl" v-for="(item, index) of installImgsInfo" :key="index">
                                    <img :src="item | smallImg(70, 70)" :alt="index">
                                </div>
                            </div>
                        </rx-viewer>
                    </div>
                    <div class="col-md-2 mt20">
                        <span class="cRed" v-if="this.twoToThreeInfo.camera === null && Number(this.twoToThreeInfo.install_state) === 0">请先去指定出库中绑定一个摄像头</span>
                        <span class="cRed" v-else-if="Number(this.twoToThreeInfo.point_state) === 0 && this.twoToThreeInfo.camera !== null && Number(this.twoToThreeInfo.install_state) === 0">请对着安装好的摄像头拍照并上传</span>
                        <span class="cRed" v-else>已安装</span>
                    </div>
                    <div class="fl mt20 tx-center">
                        <el-button type="primary" v-if="Number(this.twoToThreeInfo.install_state) === 0 && buttonIsShow" @click="_saveImgsFn()">提交</el-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer" style="padding-bottom: 1px;">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
            </div>
        </div>
    </div>
</div>
</template>
<script>
// vuex
import { mapGetters, mapMutations } from 'vuex'
// Api
import { saveImgs, selectInstallImgs } from '../../Resources/Api/index'
export default {
    props: ['type', 'role'],
    data () {
        return {
            installList: [
                '打孔', '装底座', '拧螺丝', '装摄像头', '通电', '拍照'
            ],
            imgList: [],
            installImgsInfo: [],
            buttonIsShow: false
        }
    },
    created () {
        this._selectInstallImgsFn()
        this.buttonType()
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        successUpload (value) {
            console.log(value.src)
            this.imgList.push(value.src)
        },
        _selectInstallImgsFn () {
            let params = {
                point_id: this.twoToThreeInfo.id // 点位id
            }
            selectInstallImgs(params).then((result) => {
                this.installImgsInfo = result.data.Body.installImgs
            }).catch((err) => {
                console.log(`查询安装图片错误，错误内容${err}`)
            })
        },
        // 按钮显示与隐藏
        buttonType () {
            if (this.userInfo.as_diquId === 39) {
                if (this.twoToThreeInfo.status === this.type) {
                    this.buttonIsShow = true
                } else {
                    this.buttonIsShow = false
                }
            } else {
                const userLevel = this.userInfo.as_level
                if (userLevel.length > 0) {
                    userLevel.forEach(ele => {
                        if (Number(ele) === 47) {
                            if (this.twoToThreeInfo.status === this.type) {
                                this.buttonIsShow = true
                            } else {
                                this.buttonIsShow = false
                            }
                        }
                    })
                } else {
                    this.buttonIsShow = false
                }
            }
        },
        /* 保存图片 */
        _saveImgsFn () {
            if (this.imgList === undefined || this.imgList === null || this.imgList.length === 0) {
                this.open('警告', '请选择您要保存的照片！！！')
                return
            }
            let params = {
                point_id: this.twoToThreeInfo.id, // 点位id
                camera: this.twoToThreeInfo.camera, // 监控编号
                imgs: this.imgList // 照片的集合
            }
            saveImgs(params).then((result) => {
                console.log(`保存安装图片成功`)
                // this.setUpDatePlate()
                this._selectInstallImgsFn()
                this.setUpDatePlate()
            }).catch((err) => {
                console.log(`保存安装图片错误，错误内容${err}`)
            })
        },
        // 弹框提示
        open (title, msg) {
            this.$alert(msg, title, {
                confirmButtonText: '确定',
                callback: action => {
                    this.$message({
                        type: 'info',
                        message: msg
                    })
                }
            })
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'twoToThreeInfo', 'userInfo'])
    },
    watch: {
        twoToThreeInfo () {
            this._selectInstallImgsFn()
        }
    }
}
</script>
